﻿using System;
using System.Windows;
using System.Windows.Media.Media3D;
using System.Windows.Media.Animation;

namespace SBPweb.Presentation.WpfTestApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            vpMain.AllowDrop = true;
            vpMain.Focusable = true;

            this.MouseWheel += new System.Windows.Input.MouseWheelEventHandler(MainWindow_MouseWheel);
        }

        void MainWindow_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
        {
            Point3DAnimation anim = new Point3DAnimation();
            double d = e.Delta / 500.0f;
            Vector3D vect = new Vector3D(   camMain.Position.X - camMain.LookDirection.X,
                                            camMain.Position.Y - camMain.LookDirection.Y,
                                            camMain.Position.Z - camMain.LookDirection.Z);
            vect = Vector3D.Multiply(vect, d);

            anim.From = camMain.Position;
            anim.To = Point3D.Add(camMain.Position, vect);

            anim.Duration = new Duration(TimeSpan.FromMilliseconds(500.0f));
            anim.AccelerationRatio = 0.3f;
            anim.DecelerationRatio = 0.6f;

            camMain.BeginAnimation(PerspectiveCamera.PositionProperty, anim);
        }

    }
}
